<template>

  <div class="region">
    <div class="content">
      <div class="left">
        地区:
      </div>
      <ul>
        <li :class="{active:RegionFlag==''}" @click="changRegion('')">全部</li>
        <li v-for="item in RegionArr" :key="item.value" :class="{active:RegionFlag==item.value}" @click="changRegion(item.value)">{{ item.name }}</li>
      </ul>
    </div>
  </div>
</template>


<script setup lang="ts">
//引入这个请求的方法
import {reqHospitalLevelAndRegion} from '@/api/home'
//引入组合式api函数
import {onMounted, ref} from "vue";
//使用数组存储地区的数据
let RegionArr = ref<HospitalLevelAndRegionArr>([]);
//高亮显示
let RegionFlag = ref<string>('');
import {HospitalLevelAndRegionResponseData, HospitalLevelAndRegionArr} from "@/api/home/type.ts";
//地区组件挂载完毕，获取地区的数据
onMounted(() => {


  getRegion();

});

//将请求的数据封装成函数
const getRegion = async () => {

  let result: HospitalLevelAndRegionResponseData = await reqHospitalLevelAndRegion("beijin");
  console.log(result);
  //存储全部地区的数据
  if (result.data.code == 200) {
    RegionArr.value = result.data.data;
  }

};

//点击不同地区的高亮回调
const changRegion = (region: string) => {


  //存储一下传入的参数
  RegionFlag.value = region;


  //
  $emit('getRegion',region);

}
//

let $emit=defineEmits(['getRegion']);

</script>

<script lang="ts">
export default {
  name: "Region"
}
</script>


<style scoped lang="scss">
.region {
  color: #7f7f7f;
  margin-top: 10px;

  .content {
    display: flex;

    .left {
      margin-right: 10px;
      width: 50px;


    }

    ul {
      display: flex;
      flex-wrap: wrap;

      li {
        margin-right: 10px;
        margin-bottom: 10px;

        &.active {
          color: #55a6fe;
        }
      }

      li:hover {
        color: #55a6fe;
        cursor: pointer;
      }
    }

  }
}
</style>
